<!DOCTYPE html>
<html>
    <head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>角色管理- 添加角色</title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link rel="shortcut icon" href="../favicon.ico">
	<link href="__PUBLIC__/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="__PUBLIC__/css/font-awesome.css?v=4.4.0" rel="stylesheet">
	<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="__PUBLIC__/css/animate.css" rel="stylesheet">
	<link href="__PUBLIC__/css/style.css?v=4.1.0" rel="stylesheet">
	<style type="text/css">
	    label.son { font-weight: normal; }
	</style>
    </head>
    <body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
	    <div class="row">
		<div class="col-sm-12">
		    <div class="ibox float-e-margins">
			<div class="ibox-title">
			    <h5>角色管理- <small><{$columnname}></small>
			    </h5>
			</div>
			<div class="ibox-content">
			    <form method="post" class="form-horizontal" onsubmit="return false">
				<if condition="$app_code eq ''">
<!--				    <div class="form-group">
					<label class="col-sm-2 control-label">项目</label>
					<div class="col-sm-10">
					    <select class="form-control" name="ddlapp" id="ddlapp">
						<option value="" selected="selected">-请选择项目-</option>
						<volist name="apparr" id="apparr">
						    <option value="<{$apparr.app_flag}>" <if condition="$apparr.app_flag eq $appcode">selected</if>><{$apparr.app_name}></option>
						</volist>
					    </select>
					</div>
				    </div>-->
				</if>
				<div class="form-group">
				    <label class="col-sm-2 control-label">*角色名称</label>
				    <div class="col-sm-10">
					<input type="text" class="form-control" value ="<{$name}>" placeholder="角色名称" id="txtrolename">
				    </div>
				</div>
				<div class="form-group" style="display: none;">
				    <label class="col-sm-2 control-label">*角色等级</label>
				    <div class="col-sm-10">
					<select class="form-control" id="ddlrolelevel">
					    <volist name="rolelevelarr" id="rolelevelarr">
						<option value="<{$rolelevelarr.value}>" <{$rolelevelarr.role_level_selected}>><{$rolelevelarr.text}></option>
					    </volist>
					</select>
				    </div>
				</div>
				<div class="form-group">
				    <label class="col-sm-2 control-label">*角色权限</label>
				    <div class="col-sm-10">
					<div style="padding: 15px 0; border:1px solid #cfdadd;">
					    <volist name="data" id="vo">
						<div class="form-group">
						    <div class="col-sm-2" id="role_<{$vo.id}>_box" style="text-align: right;">
							<label for="ckb_role_<{$vo.id}>" class="control-label"><input type="checkbox" name="ckb_role" id="ckb_role_<{$vo.id}>" value="<{$vo.id}>" <{$vo.checked}>><{$vo.name}></label>
						    </div>&nbsp;&nbsp;&nbsp;
						    <div class="col-sm-10" id="role_<{$vo.id}>_son_box">
							<volist name="vo.data" id="vo_son">
							    <label for="ckb_role_<{$vo_son.id}>" class="control-label son"><input type="checkbox" name="ckb_role_son" id="ckb_role_<{$vo_son.id}>" value="<{$vo_son.id}>" rel="<{$vo.id}>" <{$vo_son.checked}>><{$vo_son.name}></label>&nbsp;&nbsp;&nbsp;
							</volist>
						    </div>
						</div>
					    </volist>
					</div>
				    </div>
				</div>
				<if condition="$id gt 0">
				    <div class="form-group">
					<label class="col-sm-2 control-label">创建时间</label>
					<div class="col-sm-10 control-label" style="text-align: left;">
					    <{$ctime}>
					</div>
				    </div>
				</if>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
				    <div class="col-sm-4 col-sm-offset-2">
					<button class="btn btn-primary" type="button" onclick="role_add_submit(this)"><{$btnname}></button>&nbsp;&nbsp;&nbsp;
					<button class="btn btn-white btn-all" type="button">全选/全不选</button>&nbsp;
					<button class="btn btn-white btn-toggle" type="button">反选</button>&nbsp;
					<button class="btn btn-white" type="reset">重置</button>
				    </div>
				</div>
			    </form>
			</div>
		    </div>
		</div>
	    </div>
	</div>
	<!-- 全局js -->
	<script src="__PUBLIC__/js/jquery.min.js?v=2.1.4"></script>
	<script src="__PUBLIC__/js/bootstrap.min.js?v=3.3.6"></script>
	<!-- 自定义js -->
	<script src="__PUBLIC__/js/content.js?v=1.0.0"></script>
	<script src="__PUBLIC__/js/plugins/layer/layer.min.js"></script>
	<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
	<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	<script>
					    var labname = "<{$btnname}>";
					    var rolelisturl = "<{:U('rolelist','','shtml')}>";
					    var roleaddsubmiturl = "<{:U('roleaddsubmit','','shtml')}>";
					    var $ckb = $(":checkbox[name='ckb_role']");
					    var $ckb_son = $(":checkbox[name='ckb_role_son']");
					    var $btn_all = $(".btn-all");
					    var $btn_toggle = $(".btn-toggle");
					    $btn_all.click(function () {
						var length = $ckb_son.length;
						var length_checked = $ckb_son.filter(":checked").length;
						$ckb_son.prop("checked", length != length_checked);
						$ckb.each(function () {
						    ckb_parent_select($(this).val());
						});
					    });
					    $btn_toggle.click(function () {
						$ckb_son.each(function () {
						    var checked = $(this).prop("checked");
						    $(this).prop("checked", !checked);
						});
						$ckb.each(function () {
						    ckb_parent_select($(this).val());
						});
					    });
					    $ckb.click(function () {
						ckb_select($(this));
					    });
					    $ckb_son.click(function () {
						ckb_select($(this));
					    });
					    function ckb_select($obj)
					    {
						var checked = $obj.prop("checked");
						var val = $obj.val();
						var rel = $obj.attr("rel");
						if (rel) {
						    val = rel;
//						    var $checkbox = $("#role_" + val + "_son_box").find(":checkbox");
//						    var length = $checkbox.length;
//						    var length_checked = $checkbox.filter(":checked").length;
//						    $("#role_" + val + "_box").find(":checkbox").prop("checked", length_checked);
						    ckb_parent_select(val);
						} else {
						    $("#role_" + val + "_son_box").find(":checkbox").prop("checked", checked);
						}
					    }
					    function ckb_parent_select(val) {
						var $checkbox = $("#role_" + val + "_son_box").find(":checkbox");
						var length = $checkbox.length;
						var length_checked = $checkbox.filter(":checked").length;
						$("#role_" + val + "_box").find(":checkbox").prop("checked", length_checked);
					    }
					    function role_add_submit(obj)
					    {
						var $obj = $(obj);
						var $ddlapp = $('#ddlapp');
						var $txtrolename = $('#txtrolename');
						var $ddlrolelevel = $('#ddlrolelevel');
						var $ckb_checked = $ckb.filter(":checked");
						var $ckb_son_checked = $ckb_son.filter(":checked");
						var id = '<{$id}>';
						var appcode = $ddlapp.val();
						var rolename = $txtrolename.val();
						var rolelevel = $ddlrolelevel.val();
						var level_first_id = [];
						var level_second_id = [];
						var level_third_id = [];
						$ckb_checked.each(function () {
						    level_first_id.push($(this).val());
						});
						$ckb_son_checked.each(function () {
						    level_second_id.push($(this).val());
						});
						if (rolename == "") {
						    layer.alert('角色名称不能为空！\r\n', {title: '提示框', icon: 0});
//						    $txtrolename.focus();
						    return false;
						}
//						if (!(rolelevel > 0)) {
//						    layer.alert('角色等级不能为空！\r\n', {title: '提示框', icon: 0});
//						    $ddlrolelevel.focus();
//						    return false;
//						}
						if (level_first_id == "" || level_second_id == "") {
						    layer.alert('角色权限不能为空！\r\n', {title: '提示框', icon: 0});
						    return false;
						}
						$obj.html(labname + '中…').removeClass('btn-primary').unbind('click').removeAttr('onclick');
						//加载loading层
						var loading = layer.load(1, {
						    shade: [0.1, '#fff'] //0.1透明度的白色背景
						});
						$.post(roleaddsubmiturl, {'app_code': appcode, 'id': id, 'level_first_id': level_first_id, 'level_second_id': level_second_id, 'level_third_id': level_third_id, 'rolename': rolename, 'rolelevel': rolelevel},
							function (data) {
							    if (data.ret == '1001') {
								layer.msg(data.code, {icon: 6, time: 1000});
								layer.close(loading);
								setTimeout(function () {
								    window.location.href = rolelisturl;
								}, 1000);
							    } else {
								layer.msg(data.code, {icon: 5, time: 1000});
								layer.close(loading);
								$obj.html(labname).addClass('btn-primary').attr('onclick', 'role_add_submit(this)');
							    }
							}, 'json');
					    }

	</script>
    </body>
</html>
